package com.gnerv.battle.boot.project.guard.service.impl;

import com.gnerv.battle.boot.project.guard.mapper.MonitorMiddlewareMapper;
import com.gnerv.battle.boot.project.guard.model.bo.MonitorMiddlewareBO;
import com.gnerv.battle.boot.project.guard.model.dto.MonitorMiddlewareDTO;
import com.gnerv.battle.boot.project.guard.model.entity.MonitorMiddleware;
import com.gnerv.battle.boot.project.guard.service.MonitorMiddlewareService;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.gnerv.battle.boot.common.tools.PageTools.limitSize;
import static com.gnerv.battle.boot.common.tools.PageTools.limitStart;

/**
 * @author Gnerv LiGen
 */
@Slf4j
@Service
@AllArgsConstructor
public class MonitorMiddlewareServiceImpl implements MonitorMiddlewareService {
    
    private final MonitorMiddlewareMapper monitorMiddlewareMapper;

    @Override
    public boolean create(@NonNull MonitorMiddlewareBO monitorMiddlewareBO) {
        MonitorMiddleware monitorMiddleware = monitorMiddlewareBO.toCreateMonitorMiddleware();
        monitorMiddlewareMapper.insert(monitorMiddleware);
        return true;
    }

    @Override
    public boolean deleteByUkId(@NonNull String ukId) {
        monitorMiddlewareMapper.deleteByUkId(ukId);
        return true;
    }

    @Override
    public boolean updateByUkId(@NonNull MonitorMiddlewareBO monitorMiddlewareBO) {
        MonitorMiddleware monitorMiddleware = monitorMiddlewareBO.toUpdateMonitorMiddleware();
        monitorMiddlewareMapper.updateByUkId(monitorMiddleware);
        return true;
    }

    @Override
    public MonitorMiddlewareDTO selectByUkId(@NonNull String ukId) {
        return monitorMiddlewareMapper.selectByUkId(ukId);
    }

    @Override
    public List<MonitorMiddlewareDTO> listByName(String name, Integer page, Integer size) {
        return monitorMiddlewareMapper.listByName(name, limitStart(page, size), limitSize(size));
    }

    
}
